//
//  LevelincomeFromView.m
//  Gxj
//
//  Created by 💋索少杰 on 2017/9/13.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "LevelincomeFromView.h"
#import <SDAutoLayout.h>
//数据加载显示动画
#import "ZPPercentView.h"
//条形图
#import "UUChart.h"

@interface LevelincomeFromView ()<UUChartDataSource>
//条形图
{
    NSIndexPath *path;
    UUChart *chartView;
}
@property(nonatomic, strong) ZPPercentView *percentView;//加载数据动画
@property(nonatomic, strong) UIImageView * percentViewImage;


@end

@implementation LevelincomeFromView



- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        //等级
        [self setDengjiView];
        //收益
        [self setShouyiView];
    }
    return self;
}
#pragma mark - 等级
- (void)setDengjiView{
    //等级图标
    _imageTubiao=[[UIImageView alloc] init];
    _imageTubiao.image=[UIImage imageNamed:@"dengji"];
    [self addSubview:_imageTubiao];
    _imageTubiao.sd_layout
    .topSpaceToView(self, kHeightScale(3))
    .leftSpaceToView(self, kWidthScale(15))
    .widthIs(kWidthScale(15))
    .heightIs(kHeightScale(15));
    //等级文字
    _dengjiBut = [UIButton buttonWithType:UIButtonTypeCustom];
    //self.dengjiBut.userInteractionEnabled = YES;
    [_dengjiBut setTitle:@"等级" forState:UIControlStateNormal];
    _dengjiBut.tag = 100009;
    [_dengjiBut setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _dengjiBut.titleLabel.font=[UIFont systemFontOfSize:kWidthScale(12)];
    [self addSubview:_dengjiBut];
    _dengjiBut.sd_layout
    .topSpaceToView(self, kHeightScale(2))
    .leftSpaceToView(self.imageTubiao, kWidthScale(5))
    .widthIs(kWidthScale(25))
    .heightIs(kHeightScale(15));
    
    //背景
    _backgroundDJ=[[UIImageView alloc] init];
    _backgroundDJ.backgroundColor=[UIColor whiteColor];
    _backgroundDJ.layer.masksToBounds=YES;
    _backgroundDJ.layer.cornerRadius=8;
    _backgroundDJ.layer.shadowColor = [UIColor blackColor].CGColor;
    _backgroundDJ.layer.shadowOffset = CGSizeMake(0, 1);
    _backgroundDJ.layer.shadowOpacity = 0.2;
    //        _shadowView.layer.shadowRadius = 6.0;
    //        _shadowView.layer.cornerRadius = 6.0;
    _backgroundDJ.clipsToBounds = NO;
    [self addSubview:_backgroundDJ];
    _backgroundDJ.sd_layout
    .topSpaceToView(self.imageTubiao, kHeightScale(10))
    .leftSpaceToView(self, kWidthScale(15))
    .rightSpaceToView(self, kWidthScale(15))
    .heightIs(kHeightScale(60));
    
    
//    _percentViewImage=[[UIImageView alloc] initWithFrame:CGRectMake(kHeightScale(12), kWidthScale(12.5), kWidthScale(44), kHeightScale(44))];
//    [_backgroundDJ addSubview:_percentViewImage];
    
    //线条显示
    _lineImage=[[UIImageView alloc] init];
    _lineImage.image=[UIImage imageNamed:@"dengji-bg@2x(1)"];
    [_backgroundDJ addSubview:_lineImage];
    _lineImage.sd_layout
    .topSpaceToView(self.backgroundDJ, kHeightScale(1))
    .leftSpaceToView(self.backgroundDJ, kWidthScale(1))
    .rightSpaceToView(self.backgroundDJ, kWidthScale(1))
    .bottomSpaceToView(self.backgroundDJ, kHeightScale(1));
//    //会议
//    _imageHuiyi=[[UIImageView alloc] init];
//    _imageHuiyi.image=[UIImage imageNamed:@"dengji5"];
//    _imageHuiyi.backgroundColor=[UIColor whiteColor];
//    _imageHuiyi.layer.masksToBounds=YES;
//    _imageHuiyi.layer.cornerRadius=kWidthScale(18);
//    [_backgroundDJ addSubview:_imageHuiyi];
//    _imageHuiyi.sd_layout
//    .topSpaceToView(self.backgroundDJ, kHeightScale(9))
//    .leftSpaceToView(self.percentView, kWidthScale(12))
//    .widthIs(kWidthScale(36))
//    .heightIs(kHeightScale(36));
//    //会议文字
    _textHuiyi=[[UILabel alloc] init];
    _textHuiyi.text=@"发布会议";
    _textHuiyi.textColor=[UIColor colorWithHexString:@"#999999"];
    _textHuiyi.font=[UIFont systemFontOfSize:kWidthScale(10)];
    [_backgroundDJ addSubview:_textHuiyi];
    _textHuiyi.sd_layout
    .topSpaceToView(self.backgroundDJ, kHeightScale(41))
    .leftSpaceToView(self.backgroundDJ, kWidthScale(65.5))
    .widthIs(50)
    .autoHeightRatio(0);
//    //最佳讨论
//    _imageTaolun=[[UIImageView alloc] init];
//    _imageTaolun.image=[UIImage imageNamed:@"dengji5"];
//    _imageTaolun.backgroundColor=[UIColor whiteColor];
//    _imageTaolun.layer.masksToBounds=YES;
//    _imageTaolun.layer.cornerRadius=kWidthScale(16);
//    [_backgroundDJ addSubview:_imageTaolun];
//    _imageTaolun.sd_layout
//    .topSpaceToView(self.backgroundDJ, kHeightScale(20))
//    .leftSpaceToView(self.imageHuiyi, kWidthScale(15))
//    .widthIs(kWidthScale(32))
//    .heightIs(kHeightScale(32));
//    //最佳讨论文字
    _textTaolun=[[UILabel alloc] init];
    _textTaolun.text=@"会议最佳讨论";
    _textTaolun.textColor=[UIColor colorWithHexString:@"#999999"];
    _textTaolun.font=[UIFont systemFontOfSize:kWidthScale(10)];
    [_backgroundDJ addSubview:_textTaolun];
    _textTaolun.sd_layout
    .topSpaceToView(self.backgroundDJ, kHeightScale(5.5))
    .leftSpaceToView(self.backgroundDJ, kWidthScale(105))
    .widthIs(kWidthScale(62))
    .autoHeightRatio(0);
//    //发布创想
//    _imageChuangxiang=[[UIImageView alloc] init];
//    _imageChuangxiang.image=[UIImage imageNamed:@"dengji5"];
//    _imageChuangxiang.backgroundColor=[UIColor whiteColor];
//    _imageChuangxiang.layer.masksToBounds=YES;
//    _imageChuangxiang.layer.cornerRadius=kWidthScale(15);
//    [_backgroundDJ addSubview:_imageChuangxiang];
//    _imageChuangxiang.sd_layout
//    .topSpaceToView(self.backgroundDJ, kHeightScale(19))
//    .leftSpaceToView(self.imageTaolun, kWidthScale(20))
//    .widthIs(kWidthScale(30))
//    .heightIs(kHeightScale(30));
//    //发布创想文字
    _textChuangxiang=[[UILabel alloc] init];
    _textChuangxiang.text=@"发布创想";
    _textChuangxiang.textColor=[UIColor colorWithHexString:@"#999999"];
    _textChuangxiang.font=[UIFont systemFontOfSize:kWidthScale(10)];
    [_backgroundDJ addSubview:_textChuangxiang];
    _textChuangxiang.sd_layout
    .topSpaceToView(self.backgroundDJ, kHeightScale(42))
    .leftSpaceToView(self.backgroundDJ, kWidthScale(165.5))
    .widthIs(kWidthScale(50))
    .autoHeightRatio(0);
//    //抢位
//    _imageQiangwei=[[UIImageView alloc] init];
//    _imageQiangwei.image=[UIImage imageNamed:@"dengji5"];
//    _imageQiangwei.backgroundColor=[UIColor whiteColor];
//    _imageQiangwei.layer.masksToBounds=YES;
//    _imageQiangwei.layer.cornerRadius=kWidthScale(18);
//    [_backgroundDJ addSubview:_imageQiangwei];
//    _imageQiangwei.sd_layout
//    .topSpaceToView(self.backgroundDJ, kHeightScale(20))
//    .leftSpaceToView(self.imageChuangxiang, kWidthScale(14))
//    .widthIs(kWidthScale(36))
//    .heightIs(kHeightScale(36));
//    //抢位文字
    _textQiangwei=[[UILabel alloc] init];
    _textQiangwei.text=@"创想最佳讨论";
    _textQiangwei.textColor=[UIColor colorWithHexString:@"#999999"];
    _textQiangwei.font=[UIFont systemFontOfSize:kWidthScale(10)];
    [_backgroundDJ addSubview:_textQiangwei];
    _textQiangwei.sd_layout
    .topSpaceToView(self.backgroundDJ, kHeightScale(8.5))
    .leftSpaceToView(self.backgroundDJ, kWidthScale(204.5))
    .widthIs(kWidthScale(62))
    .autoHeightRatio(0);
//    //辩论
//    _imageBianlun=[[UIImageView alloc] init];
//    _imageBianlun.image=[UIImage imageNamed:@"dengji5"];
//    _imageBianlun.backgroundColor=[UIColor whiteColor];
//    _imageBianlun.layer.masksToBounds=YES;
//    _imageBianlun.layer.cornerRadius=kWidthScale(15);
//    [_backgroundDJ addSubview:_imageBianlun];
//    _imageBianlun.sd_layout
//    .topSpaceToView(self.backgroundDJ, kHeightScale(18))
//    .leftSpaceToView(self.imageQiangwei, kWidthScale(16))
//    .widthIs(kWidthScale(30))
//    .heightIs(kHeightScale(30));
//    //辩论文字
    _textBianlun=[[UILabel alloc] init];
    _textBianlun.text=@"发布辩论";
    _textBianlun.textColor=[UIColor colorWithHexString:@"#999999"];
    _textBianlun.font=[UIFont systemFontOfSize:kWidthScale(10)];
    [_backgroundDJ addSubview:_textBianlun];
    _textBianlun.sd_layout
    .topSpaceToView(self.backgroundDJ, kHeightScale(44))
    .leftSpaceToView(self.backgroundDJ, kWidthScale(266.5))
    .widthIs(kWidthScale(50))
    .autoHeightRatio(0);
    
    //数据显示
    _percentView=[[ZPPercentView alloc] initWithFrame:CGRectMake(kWidthScale(10.5), kHeightScale(8.5), kWidthScale(43), kHeightScale(43))];
//    [_percentView updateZPPercent:@(100.0).floatValue openAnimation:YES font:[UIFont systemFontOfSize:kWidthScale(18)]];
    [_percentView updateZPPercent:@(100.0).floatValue openAnimation:YES font:[UIFont systemFontOfSize:kWidthScale(16)] sizeColor:[UIColor colorWithHexString:@"#ffffff"] isPercentage:NO];
    _percentView.backgroundColor = [UIColor clearColor];
    _percentView.layer.masksToBounds=YES;
    _percentView.layer.cornerRadius=kWidthScale(43/2);
    _percentView.layer.borderWidth = 1;
    _percentView.layer.borderColor = [[UIColor clearColor] CGColor];
    [_lineImage addSubview:_percentView];
    
    
}
#pragma mark - 收益
- (void)setShouyiView{
    
    //账本图标
    _imageTubiaoSy=[[UIImageView alloc] init];
    _imageTubiaoSy.image=[UIImage imageNamed:@"shouyi"];
    //_imageTubiaoSy.backgroundColor=[UIColor orangeColor];
    [self addSubview:_imageTubiaoSy];
    _imageTubiaoSy.sd_layout
    .topSpaceToView(self.backgroundDJ, kHeightScale(20))
    .leftSpaceToView(self, kWidthScale(15))
    .widthIs(kWidthScale(15))
    .heightIs(kHeightScale(15));
    //账本文字
    _shouyiBut=[[UIButton alloc] init];
    _shouyiBut = [UIButton buttonWithType:UIButtonTypeCustom];
    [_shouyiBut setTitle:@"账本" forState:UIControlStateNormal];
    _shouyiBut.tag = 1000010;
    [_shouyiBut setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _shouyiBut.titleLabel.font=[UIFont systemFontOfSize:kWidthScale(12)];
    [self addSubview:_shouyiBut];
    _shouyiBut.sd_layout
    .topSpaceToView(self.backgroundDJ, kHeightScale(20))
    .leftSpaceToView(self.imageTubiaoSy, kWidthScale(5))
    .widthIs(kWidthScale(25))
    .heightIs(kHeightScale(15));
    
    
    //条形图
    chartView = [[UUChart alloc]initwithUUChartDataFrame:CGRectMake(kWidthScale(10), kHeightScale(130), [UIScreen mainScreen].bounds.size.width-20, kHeightScale(180))
                                            withSource:self
                                            withStyle:self==UUChartLineStyle];
    //chartView.backgroundColor=[UIColor orangeColor];
    [chartView showInView:self];
    
    //账房
    _imageTubiaoZF=[[UIImageView alloc] init];
    _imageTubiaoZF.image=[UIImage imageNamed:@"sifangqian"];
    [self addSubview:_imageTubiaoZF];
    _imageTubiaoZF.sd_layout
    .topSpaceToView(chartView, kHeightScale(20))
    .leftSpaceToView(self, kWidthScale(15))
    .widthIs(kWidthScale(15))
    .heightIs(kHeightScale(15));
    //账房
    _zhangFanBut=[[UIButton alloc] init];
    [_zhangFanBut setTitle:@"私房钱" forState:UIControlStateNormal];
    [_zhangFanBut setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _zhangFanBut.titleLabel.font=[UIFont systemFontOfSize:kWidthScale(12)];
    [self addSubview:_zhangFanBut];
    _zhangFanBut.sd_layout
    .topSpaceToView(chartView, kHeightScale(20))
    .leftSpaceToView(self.imageTubiaoZF, kWidthScale(5))
    .widthIs(kWidthScale(40))
    .heightIs(kHeightScale(15));
    //图片横线
    _backgroundZF = [[UIImageView alloc] init];
    _backgroundZF.image = [UIImage imageNamed:@"cangqian"];
    _backgroundZF.contentMode = UIViewContentModeScaleAspectFit;
    //_backgroundZF.backgroundColor=[UIColor redColor];
    [self addSubview:_backgroundZF];
    _backgroundZF.sd_layout
    .topSpaceToView(self.imageTubiaoZF, kHeightScale(10))
    .leftSpaceToView(self, kWidthScale(15))
    .rightSpaceToView(self, kWidthScale(15))
    .heightIs(kHeightScale(65));
    
//    _ballBackground=[[UIImageView alloc] init];
//    _ballBackground.image=[UIImage imageNamed:@"shouru2"];
//    [self addSubview:_ballBackground];
//    _ballBackground.sd_layout
//    .topSpaceToView(self.imageTubiaoZF, kHeightScale(25))
//    .leftSpaceToView(self, kWidthScale(17))
//    .widthIs(kWidthScale(40))
//    .heightIs(kHeightScale(40));
//    
//    _ballBackground1=[[UIImageView alloc] init];
//    _ballBackground1.image=[UIImage imageNamed:@"shouru2"];
//    [self addSubview:_ballBackground1];
//    _ballBackground1.sd_layout
//    .topSpaceToView(self.imageTubiaoZF, kHeightScale(33))
//    .leftSpaceToView(self.ballBackground, kWidthScale(17))
//    .widthIs(kWidthScale(30))
//    .heightIs(kHeightScale(30));
    
    //总金额
    _jine=[[UILabel alloc] init];
    _jine.text=@"总金额";
    _jine.textColor=[UIColor colorWithHexString:@"#333333"];
    _jine.font=[UIFont systemFontOfSize:kWidthScale(10)];
    [_backgroundZF addSubview:_jine];
    _jine.sd_layout
    .topSpaceToView(self.backgroundZF, kHeightScale(36))
    .leftSpaceToView(self.backgroundZF, kWidthScale(5))
    .widthIs(kWidthScale(40))
    .autoHeightRatio(0);
    //藏钱
    _cangqian=[[UILabel alloc] init];
    _cangqian.text=@"藏钱";
    _cangqian.textColor=[UIColor whiteColor];
    _cangqian.font=[UIFont systemFontOfSize:kWidthScale(11)];
    [self addSubview:_cangqian];
    _cangqian.sd_layout
    .topSpaceToView(self.imageTubiaoZF, kHeightScale(51))
    .rightSpaceToView(self, kWidthScale(17))
    .widthIs(kWidthScale(30))
    .autoHeightRatio(0);
}


#pragma mark - @条形图
- (NSArray *)getXTitles:(int)num
{
    NSMutableArray *xTitles = [NSMutableArray array];
    for (int i=1; i<num; i++) {
        NSString * str = [NSString stringWithFormat:@"星期%d",i];
        [xTitles addObject:str];
    }
    return xTitles;
}
//横坐标标题数组
- (NSArray *)UUChart_xLableArray:(UUChart *)chart
{
    

                return [self getXTitles:8];


    //return [self getXTitles:200];
    //return nil;
}
//数值多重数组
- (NSArray *)UUChart_yValueArray:(UUChart *)chart
{
    //内容
    //NSArray *ary = @[@"22",@"44",@"15",@"40",@"42"];
    NSArray *ary1 = @[@"22",@"54",@"15",@"30",@"42",@"100",@"43"];
    NSArray *ary2 = @[@"76",@"34",@"54",@"23",@"16",@"32",@"17"];
    //NSArray *ary3 = @[@"3",@"12",@"25",@"55",@"52",@"40",@"100"];
    //NSArray *ary4 = @[@"23",@"42",@"25",@"15",@"30",@"42",@"32",@"40",@"42",@"25",@"33"];
    
                    return @[ary1,ary2];

            //return @[ary1,ary2];

            //return @[ary1];

}
//颜色数组
- (NSArray *)UUChart_ColorArray:(UUChart *)chart
{
    return @[UUGreen,UURed,UUBrown];
}
//显示数值范围
- (CGRange)UUChartChooseRangeInLineChart:(UUChart *)chart
{
    if (self) {
        return CGRangeMake(100, 10);
    }
//    if (path.section==1 && path.row==0) {
//        return CGRangeMake(60, 10);
//    }
//    if (path.row==1) {
//        return CGRangeMake(80, 0);
//    }
    return CGRangeZero;

}


//标记数值区域
- (CGRange)UUChartMarkRangeInLineChart:(UUChart *)chart
{
    if (path.row==2) {
        return CGRangeMake(25, 75);
    }
    return CGRangeZero;
}
//判断显示横线条
- (BOOL)UUChart:(UUChart *)chart ShowHorizonLineAtIndex:(NSInteger)index
{
    return YES;
}
//判断显示最大最小值
- (BOOL)UUChart:(UUChart *)chart ShowMaxMinAtIndex:(NSInteger)index
{
    return path.row==1;
}

@end
